package neuron;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class AbstractFiber {
	
	public Segment root;
	
	private Map<String, Object> metadata = new HashMap<String, Object>();
	
	public void addMetadata(String key, Object obj) {
		metadata.put(key, obj);
	}
	
	public void getMetadata(String key) {
		metadata.get(key);
	}
	
	/**
	 * Get all coordinates in this axon/dendrite.
	 * @return
	 */
	public List<Coord> getAllCoordinates()
	{
		List<Coord> coords = new ArrayList<Coord>();
		List<Segment> segs = new ArrayList<Segment>();
		if (root == null) return coords;
		root.collectSegments(segs);
		for (Segment s : segs) {
			coords.addAll(s.getPoints());
		}
		return coords;
	}
	
	public Segment getRootSegment()
	{
		return root;
	}
	
	public List<Segment> getTerminalSegments()
	{
		return root.getTerminalSegments();
	}
	
	/**
	 * Get all ending points (i.e. points with no continuation)
	 * @return
	 */
	public List<Coord> getEndPoints()
	{
		List<Coord> lst = new ArrayList<Coord>();
		
		// go through all segments
		List<Segment> segs = new ArrayList<Segment>();
		root.collectSegments(segs);
		for (Segment s : segs) {
			// if terminal segment, add last coordinate to lst
			if (s.isTerminalSegment()) {
				lst.add(s.lastCoordinate());
			}
		}
		
		return lst;
	}
}
